<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>部门</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no">
<link rel="stylesheet" href="layui/css/layui.css" media="all">
<link rel="stylesheet" href="./css/x-admin.css" media="all">
</head>
<body>
	<div class="x-nav">
		<span class="layui-breadcrumb"> <a><cite>首页</cite></a> <a><cite>信息管理</cite></a>
			<a><cite>部门列表</cite></a>
		</span> <a class="layui-btn layui-btn-small"
			style="line-height: 1.6em; margin-top: 3px; float: right"
			href="javascript:location.replace(location.href);" title="刷新"><i
			class="layui-icon" style="line-height: 30px">ဂ</i></a>
	</div>
	<div class="x-body">
		<xblock>
		<button class="layui-btn layui-btn-danger" onclick="delAll()">
			<i class="layui-icon">&#xe640;</i>批量删除
		</button>
		<button class="layui-btn"
			onclick="dept_add('添加部门','DeptAdd.jsp','500','450')">
			<i class="layui-icon">&#xe608;</i>添加
		</button>
		<form style="display: inline-block">
			<div class="layui-input-inline">
				<input class="layui-input" type="text" name="keyword" id="keyword" 
			    placeholder="请输入要查询的部门名称" value="${keyword}">
			</div>
			<button class="layui-btn" type="submit" lay-submit="" lay-filter="sreach" name="op" value="">
					<i class="layui-icon">&#xe615;</i>
			</button>
		</form>
		<span class="x-right" style="line-height: 40px">共有数据：<span
			class="layui-badge">${pd.totalCount}</span> 条
		</span>
		</xblock>
		<table class="layui-table">
			<thead >
				<tr>
					<th><input type="checkbox" value="1" name="all" id="all"></th>
					<th>部门号</th>
					<th>部门名</th>
					<th>主管号</th>
					<th>主管名</th>
					<th>操作</th>
				</tr>
			</thead>
			<tbody>
				<c:if test="${pd == null}">
					<c:redirect url="DeptServlet"></c:redirect>
				</c:if>
				<c:if test="${pd != null }">
					<c:forEach items="${pd.data}" var="dept">
						<tr>
							<td><input type="checkbox" value="${dept.deptNo}" name="one" class="one"></td>
							<td>${dept.deptNo}</td>
							<td>${dept.deptName}</td>
							<td>${dept.empNo}</td>
							<td>${dept.empName}</td>
							<td class="td-manage">
								<a title="编辑" href="javascript:;"
									onclick="dept_edit('编辑','DeptEdit.jsp?deptNo=${dept.deptNo}&deptName=${dept.deptName}&empNo=${dept.empNo}','4','500','450')"
									class="ml-5" style="text-decoration: none"> 
									<i class="layui-icon">&#xe642;</i>
								</a> 
								<a title="删除"
								href="javascript:;" onclick="dept_del(this,${dept.deptNo})"
								style="text-decoration: none"> <i class="layui-icon">&#xe640;</i></a>
							</td>
						</tr>
					</c:forEach>
				</c:if>
			</tbody>
		</table>

		<div id="page" style="text-align: center"></div>
	</div>
	<script src="js/jquery-2.0.3.js" charset="utf-8"></script>
	<script src="layui/layui.js" charset="utf-8"></script>
	<script src="./js/x-layui.js" charset="utf-8"></script>
	<script>
	layui.use(['laypage', 'layer'], function(){
		  var laypage = layui.laypage,
		  layer = layui.layer;
		//完整功能
		//elem [显示位置]  count [总数据数]  curr [当前页码]  
		//limit [当前页码的数据数]  theme [颜色]
		laypage.render({
			elem : 'page',    
			count : ${pd.totalCount},
			curr: ${pd.page},
			limit : ${pd.pageSize},
			theme: 'lightblue',	
			layout : [ 'prev', 'page', 'next' ],
			jump : function(obj,first) { //跳转页面时的动作
				if(!first){
					location.href="DeptServlet?page="+obj.curr+"&keyword="+$("#keyword").val();
				}
			}
		});
	});

	
	/*用户-添加*/
	function dept_add(title, url, w, h) {
		x_admin_show(title, url, w, h);
	}
	// 用户-编辑
	function dept_edit(title, url, id, w, h) {
			x_admin_show(title, url, w, h);
		}
	/*用户-删除*/
	function dept_del(obj, id) {
		layer.confirm('确认要删除'+id+'吗？', {
			icon : 3,
			title : '提示信息'
		}, function(index) {
			$.ajax({
				type : "post",
				url : "DeptServlet",
				data : {
					deptno : id,
					op : "del"
				},
				success:function(data){
					if(data.code == 200){
						layer.msg(data.msg,{icon:1,time:1000});
	                    setTimeout(function(){
	                        window.parent.location.reload();
	                        var index = parent.layer.getFrameIndex(window.name);
	                        parent.layer.close(index);
	                    },1000);
	                    return false;
					}else{
						layer.msg(data.msg,{icon:5,time:2000});
	                    return false;
					}
			   },
			   dataType:"json"
		  });
			return false;
		});
	}
	
	/* 复选框 */
	$(function(){
		$("#all").click(function(){
			$("input[class = one ]").prop("checked",this.checked);
		});
	})
	/* 批量删除提交 */
	function delAll() {
		var result = "";
		$(".one").each(function(){
			if($(this).is(':checked')){
				result += $(this).val()+",";
			}else{}
		})
		layer.confirm('确认要删除吗？', {
			icon: 3,
			title: '提示信息'
		}, function(index) {
			$.ajax({
				type:"post",
				url:"DeptServlet",
				data:{
					r : result,
					op : "delAll"
				},
				success:function(data){
					if(data.code == 200){
						layer.msg(data.msg,{icon:1,time:1000});
	                    setTimeout(function(){
	                        window.parent.location.reload();
	                        var index = parent.layer.getFrameIndex(window.name);
	                        parent.layer.close(index);
	                    },1000);
	                    return false;
					}else{
						layer.msg(data.msg,{icon:5,time:2000});
	                    return false;
					}
				},
				dataType:"json"
			});
			return false;
		});
	}
	</script>

</body>
</html>